1800D - Remove Two Letters - CodeForces Solution


data structures hashing strings

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
#include <iostream>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#define forn(i, n)for(int i = 0; i < int(n); i++)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const double dinf=1e300;
const ll INF=1e18;
const int Mod=1e9+7;
const int maxn=5e5+10;
const ll N = 1'000'000'000'000L;
const int MaX = 1e3 + 11;
unordered_set<ll> cubes;
void Ahmos()
{
    cin.tie(NULL);
    cout.tie(NULL);
    ios_base::sync_with_stdio(false);
}
void Ahmos2()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

bool isPrime(long long n)
{

    if(n<=1)
        return false;
    for(long long i=2; i<=sqrt(n); i++)
    {
        if(n%i==0)
            return false;
    }

    return true;

}
ll fact(ll a)
{
    ll sum=1;
    for(int i=1; i<=a; i++)
    {
        sum*=i;
    }
    return sum;
}

void so1()
{
    int n;cin>>n;
    string s;cin>>s;
    long long c=1;
    for(int i=2;i<n;i++)
    {
        if(s[i]==s[i-2])continue;
        c++;
    }
    cout<<c<<endl;

}
int main()
{
    Ahmos();
    int t=1;
    cin>>t;
    while(t--)
        so1();








}


Comments

Submit
0 Comments
More Questions

380. Insert Delete GetRandom O(1)
332. Reconstruct Itinerary
368. Largest Divisible Subset
377. Combination Sum IV
322. Coin Change
307. Range Sum Query - Mutable
287. Find the Duplicate Number
279. Perfect Squares
275. H-Index II
274. H-Index
260. Single Number III
240. Search a 2D Matrix II
238. Product of Array Except Self
229. Majority Element II
222. Count Complete Tree Nodes
215. Kth Largest Element in an Array
198. House Robber
153. Find Minimum in Rotated Sorted Array
150. Evaluate Reverse Polish Notation
144. Binary Tree Preorder Traversal
137. Single Number II
130. Surrounded Regions
129. Sum Root to Leaf Numbers
120. Triangle
102. Binary Tree Level Order Traversal
96. Unique Binary Search Trees
75. Sort Colors
74. Search a 2D Matrix
71. Simplify Path
62. Unique Paths